import React, { PureComponent } from 'react';
import { connect } from 'react-redux'
import { Redirect, Route, Switch } from 'react-router-dom';
import PropTypes from 'prop-types'
import Header from '../../component/Login/Header/index';
import Banner from '../../component/Login/Banner/index';
import ModalLogin from '../../component/Login/Modal_Login/index';
import SMSLogin from '../../component/Login/SMS_Login/index';
import Footer from '../../component/Login/Footer/index';
import {
  LOGIN_PATH, PAN_PATH_HOME,
  SMS_LOGIN_PATH
} from '../../constant';

class Login extends PureComponent {

  static propTypes = {
    user: PropTypes.object,
    history: PropTypes.object
  }

  // 查询当前用户是否已经登录
  userDidLogin = () => {
    const { user, history } = this.props
    if (user && user.id) {
      // 跳转网盘页面
      history.push(PAN_PATH_HOME)
    }
  }

  componentDidMount () {
    this.userDidLogin()
  }

  render () {
    return (
      <>
        <Header/>
        <Banner/>
        <Switch>
          <Route path={SMS_LOGIN_PATH} component={SMSLogin}/>
          <Route path={LOGIN_PATH} component={ModalLogin}/>
          <Redirect to={LOGIN_PATH}/>
        </Switch>
        <Footer/>
      </>
    );
  }
}

export default connect(
  (state) => ({
    user: state.user
  }),
  {
  }
)(Login);
